package com.baizhi.controller;

import com.baizhi.entity.User;
import com.baizhi.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("user")
public class UserController {
    private static final Logger log = LoggerFactory.getLogger(UserController.class);
    @Autowired
    private UserService userService;

    @RequestMapping("queryAllPage")
    public Map<String,Object> queryAllPage(int page){
        int size=3;
        Map<String, Object> map = userService.queryAllPage(page, size);
        return map;
    }
    @RequestMapping("updateStatus")
    public void updateStatus(@RequestParam("status") int status, @RequestParam("id")String id){
        userService.updateStatus(status,id);
    }
    @RequestMapping("deleteUser")
    public void deleteUser(String id){
        userService.deleteUser(id);
    }


    @RequestMapping("addUser")
    public void addUser(MultipartFile photo,String username,String phone,String brief){
        log.info("file："+photo);
        log.info("username："+username);
        log.info("phone："+phone);
        log.info("brief："+brief);
        User user = new User(null, username, phone, null, brief, null, null,null);
        userService.addUser(photo,user);
    }



}
